package com.eies.business.directory.xxzygl;

import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.URLEncoder;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.eies.engine.common.ConfigUtil;


public class DownloadServelet extends HttpServlet {
	public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {
		BufferedOutputStream bos = null;
		FileInputStream fis = null;
		String wj = request.getParameter("wjmc");
		String fileName = wj;
		String filePath = ConfigUtil.xxsqfilePath+fileName;
		if((filePath != null) && (!"".equals(filePath)))
			try {
				String disposition = "attachment;filename="	+ URLEncoder.encode(fileName, "UTF-8");
				response.setContentType("application/x-msdownload;charset=UTF-8");
				response.setHeader("Content-disposition", disposition);
				fis = new FileInputStream(filePath);
				bos = new BufferedOutputStream(response.getOutputStream());
				byte[] buffer = new byte[2048];
				while (fis.read(buffer) != -1)
					bos.write(buffer);
			} catch (IOException e) {
				//e.printStackTrace();

				if (fis != null)
					try {
						fis.close();
					} catch (IOException localIOException1) {
					}
				if (bos != null)
					try {
						bos.close();
					} catch (IOException localIOException2) {
					}
			} finally {
				if (fis != null)
					try {
						fis.close();
					} catch (IOException localIOException3) {
					}
				if (bos != null)
					try {
						bos.close();
					} catch (IOException localIOException4) {
					}
			}

	}
}
